/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.firebird.base.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author qiuxj
 * @date 2009-11-14
 */
public class DateUtil {

	  private static String defaultDatePattern = "yyyy-MM-dd HH:mm:ss";

	  public static String getDatePattern()
	  {
	    return defaultDatePattern;
	  }

	  public static String getToday()
	  {
	    Date today = new Date();
	    return format(today);
	  }

	  public static String format(Date date)
	  {
	    return format(date, getDatePattern());
	  }

	  public static String format(Date date, String pattern)
	  {
	    String returnValue = "";

	    if (date != null) {
	      SimpleDateFormat df = new SimpleDateFormat(pattern);
	      returnValue = df.format(date);
	    }

	    return returnValue;
	  }

	  public static Date parse(String strDate)
	    throws ParseException
	  {
	    return parse(strDate, getDatePattern());
	  }

	  public static Date parse(String strDate, String pattern)
	    throws ParseException
	  {
	    SimpleDateFormat df = new SimpleDateFormat(pattern);
	    return df.parse(strDate);
	  }

	  public static Date addMonth(Date date, int n)
	  {
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    cal.add(2, n);
	    return cal.getTime();
	  }

	  public static Date addDay(Date date, int n)
	  {
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    cal.add(7, n);
	    return cal.getTime();
	  }

	  public static String addMinute(Date date, int n)
	  {
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    cal.add(12, n);
	    return format(cal.getTime());
	  }

	  public static String addSecond(Date date, int n)
	  {
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    cal.add(13, n);
	    return format(cal.getTime());
	  }
	
}
